package com.swcn.u_pet;

import java.text.SimpleDateFormat;
import java.util.Date;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.view.View;

public class MainView extends View{
	    ControlUnit activity;
	    static int count = 0;
	    static int steps = 0;
	    private int n_step;
	    //private Button Graphbutton;
	    private int confirm = 0;
	    private String[] Message = {"You can do it!","Good!!","Be careful"};
	    public MainView(Context context){
	    	super(context);
	    	
	    	activity = (ControlUnit)context;
	    	
	    	setBackgroundColor(Color.rgb(0,0,0));
		}
	   
	    
	public void Count(){
		steps++;
	}
	
	public int getStep(){
		return steps;
	}
	
	public void setConfirm(){
		confirm = 0;
	}
	
	public void clear(){
		steps = 0;
	}
	    
	protected void onDraw(Canvas canvas){
		count++;
		
		Paint p = new Paint();
		
		p.setAntiAlias(true);
		p.setTextSize(32.0f);
		p.setColor(Color.rgb(255,255,255 ));
		AccelerometerListener listener = activity.getAccelerometerListener();
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy.MM.dd '\' hh:mm:ss a ");
		Date date = new Date();
		
//		canvas.drawText("AccelX: "+listener.getAccelX(),8,40,p);
//		canvas.drawText("AccelY: "+listener.getAccelY(),8,80,p);
//		canvas.drawText("AccelZ: "+listener.getAccelZ(),8,120,p);
//		canvas.drawText("Azimuth: "+listener.getAzimuth(),8,160,p);
//		canvas.drawText("Pitch: "+listener.getPitch(),8,200,p);
//		canvas.drawText("Roll: "+listener.getRoll(),8,240,p);
		canvas.drawText("Time:"+sdf.format(date),8,40,p);
		canvas.drawText("Steps: "+steps,8,80,p);
		canvas.drawText("Distance: "+steps*60,8,120,p);
		if(activity.getFlag() == 1){
			if(confirm == 1){
				canvas.drawText("now Steps: "+n_step,8,160,p);
			}
			else{
			n_step = steps;
			canvas.drawText("now Steps: "+n_step,8,160,p);
			confirm = 1;
			}
		}
		switch(activity.getEvaluation()){
			case 1:
				canvas.drawText("Evaluation: "+Message[2],8,200,p);
				break;
			case 2:
				canvas.drawText("Evaluation: "+Message[1],8,200,p);
				break;
			case 0:	
				canvas.drawText("Evaluation: "+Message[0],8,200,p);
				break;	
			default:
				break;
			}
				
		//canvas.drawText("Count:"+count,8,400,p);
		if(activity.getFlag() == 1){
		canvas.drawText("U_pet: "+activity.getP_parameter(),8,240,p);
		canvas.drawText("User: "+activity.getL_parameter(),8,280,p);
		canvas.drawText("Other User: "+activity.getP_parameter2(),8,320,p);
		canvas.drawText("Other Ramda "+activity.getRamda(),8,360,p);
		canvas.drawText("balance:"+(activity.getL_parameter()/activity.getP_parameter()),8,400,p);
		}
		if(activity.getName() != null){
			canvas.drawText("User Name: "+activity.getName(),8,400,p);
		}
	}
}